package com.tangpian.sna.core.analysis.lda.algorithm;

import java.io.FileNotFoundException;
import java.io.IOException;

public class LDAPredictor {

	private Inferencer inferencer;

	// ////输入模型文件地址初始化
	public LDAPredictor(String dir, String modelName) {
		LDAOption option = new LDAOption();

		option.dir = dir;
		option.modelName = modelName;
		option.inf = true;
		inferencer = new Inferencer();
		inferencer.init(option);
	}

	// ///////推断新数据
	public Model inference(String data) {
		String[] docs = new String[1];
		docs[0] = data;
		return inferencer.inference(docs);
	}

	public static void main(String[] args) throws FileNotFoundException,
			IOException, ClassNotFoundException {

		LDAPredictor predictor = new LDAPredictor(
				"/Users/shydow/space/dev/sna/lda/res/test/", "model-final");

		String input = "Snow monkeys of Japan's Hell Valley";
		Model model = predictor.inference(input);

		double[] dist = model.theta[0];
		for (double d : dist) {
			System.out.print(d + " ");
		}

		//
		// LDAPredictor predictor2 = new
		// LDAPredictor("D:/arec/ldaInferencer.model");
		// System.out.println("Inference:");
		// Model model = predictor2.inference("金牌 佳能 单反 广角 变焦 红圈 镜头");
		//
		// double [] dist = model.theta[0];
		// Arrays.sort(dist);
		// for (double d : dist) {
		// System.out.println(d + " ");
		// }

	}

}
